
# 特性属性的示例

class Student:
    def __init__(self, s):
        self.__score = s
    @property
    def score(self):
        return self.__score
    @score.setter
    def score(self, s):
        if s < 0 or s > 100:
            raise ValueError('分数错误')
        self.__score = s

stu1 = Student(59)
# 安全
print(stu1.score)  # 调用 stu1.get_score()
stu1.score = 9000  # 调用 stu1.set_score(9000)
print(stu1.score)